package com.lcy.mybatis.generator.plugin.element;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;

/**
 * <p>创建时间：2017/5/5 16:39</p>
 *
 * @author 娄存银
 * @version 1.0
 */
public class SelectAllElement extends CustomerSqlElement{
    private static final String SQL = "select\n" +
            "    <include refid=\"Base_Column_List\" /> \n" +
            "    from %s \n" +
            "    <if test=\"limit != null and limit.length() > 0\">\n" +
            "    limit ${limit}\n" +
            "    </if>";
    public SelectAllElement(IntrospectedTable table) {
        super(table);
    }

    @Override
    protected void initXmlElement() {
        xmlElement = selectElement();
    }

    @Override
    protected void initMethod() {
        method = new Method(getId());
        method.setReturnType(modelListType());

        method.addParameter(new Parameter(TYPE_STRING,LIMIT,annotation(LIMIT)));
    }

    @Override
    protected String getId() {
        return "selectAll";
    }

    @Override
    protected String getSql() {
        return SQL;
    }
}
